package com.fulei.device;

import android.util.Log;

import com.bjfl.saleManager.util.LogUtil;
import com.fulei.logic.GoodsOperate;
import com.bjfl.bean.GoodsLineMsg;
import com.log.LatteLogger;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class TGGoodsDevice {
    private String deviceType;
    private String comNo;
    private String baudRate;

    public TGGoodsDevice(String devType, String com, String brn) {
        this.deviceType = devType;
        this.comNo = com;
        this.baudRate = brn;
    }

    public int goodsReset() {
        int return_data = 0;
        try {
            if ("TGG1".equals(this.deviceType)) {
                GoodsOperate.comNo = this.comNo;
                GoodsOperate.baudRate = this.baudRate;
                return_data = GoodsOperate.goodsReset();
            }
        } catch (Exception ex) {
            LogUtil.writeExceptionLog("goodsReset 异常:" + ex.getMessage());
            return_data = -1;
        }
        return return_data;
    }
    public String getGoodsLineState(byte layer){
        String returnData = "";
        GoodsOperate.comNo = this.comNo;
        GoodsOperate.baudRate = this.baudRate;
        returnData = GoodsOperate.getGoodsLineState(layer);
        return returnData;
    }
    public String goodsrangecheck_opendoor(byte address,int lineNum) {
        String returnData = "";
        try {
            if ("TGG1".equals(this.deviceType)) {
                GoodsOperate.comNo = this.comNo;
                GoodsOperate.baudRate = this.baudRate;
                returnData = GoodsOperate.goodsRangeCheckOpenDoor(address,lineNum);
            }
        } catch (Exception ex) {
            LogUtil.writeExceptionLog("goodsRangeCheckOpenDoor 异常:" + ex.getMessage());
            Log.e("异常：", ex.getMessage());
            ex.printStackTrace();
            returnData = "";
        }
        return returnData;
    }

    public String goodsRangeCheckCloseDoor(byte address, byte dataCmd, String userScanId,int lineNum) {
        String return_data = "";
        try {
            if ("TGG1".equals(this.deviceType)) {
                GoodsOperate.comNo = this.comNo;
                GoodsOperate.baudRate = this.baudRate;
                return_data = GoodsOperate.goodsRangeCheckCloseDoor(address, dataCmd, userScanId,lineNum);
            }
        } catch (Exception ex) {
            LogUtil.writeExceptionLog("goodsRangeCheckOpenDoor 异常:" + ex.getMessage());
            return_data = "";
        }
        return return_data;
    }

    public List<GoodsLineMsg> getLineGoodsMsgWithCloseDoor(byte address, byte dataCmd, String userScanId,
                                                           int lineNum) {
        List<GoodsLineMsg> goodsLineMsgList = new ArrayList<>();
        try {
            if ("TGG1".equals(this.deviceType)) {
                GoodsOperate.comNo = this.comNo;
                GoodsOperate.baudRate = this.baudRate;
                goodsLineMsgList = GoodsOperate.getGoodsLineMsgWithSingle(address, dataCmd,userScanId,lineNum);
            }
        } catch (Exception ex) {
            LogUtil.writeExceptionLog("goodsRangeCheckOpenDoor 异常:" + ex.getMessage());
            LatteLogger.e("exception",ex.getMessage());
           return Collections.EMPTY_LIST;
        }
        return goodsLineMsgList;
    }

}
